/**
 * Author@ Cheng Feitian
 * Date: 2021-4-4
 * Description: 菱形继承
 */

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;
const int maxn = 1024;

//动物类
class Animal
{
public:
    int m_Age;
};
//利用虚继承    解决菱形继承问题
//继承之前  加上关键字 virtual 变为虚继承
//Animal类称为虚基类
//羊类
class Sheep : virtual public Animal
{
};

//驼类
class Camel : virtual public Animal
{
};

//羊驼类
class Alpaca : public Sheep, public Camel
{
};

void test01(){
    Alpaca alpaca;
    alpaca.Sheep::m_Age = 18;
    alpaca.Camel::m_Age = 28;
    //当菱形继承时，两个父类拥有相同的数据，需要加作用域区分
    cout << "alpaca.Sheep::m_Age = " << alpaca.Sheep::m_Age << endl;
    cout << "alpaca.Camel::m_Age = " << alpaca.Camel::m_Age << endl;
    cout << "alpaca.m_Age = " << alpaca.m_Age << endl;

    //这份数据  事实上只需要有一份即可  菱形继承导致数据有两份  资源浪费

}

int main()
{
    test01();
    return 0;
}
